#include "stdafx.h"
#include "Semaphore.h"

Semaphore::Semaphore(unsigned long count) : m_count(count) {}

void Semaphore::Signal()
{
	{
		std::unique_lock<std::mutex> lock(m_mutex);
		++m_count;
	}
	m_cv_uptr.notify_one();
}

void Semaphore::Wait()
{
	std::unique_lock<std::mutex> lock(m_mutex);
	while (m_count == 0) { // we may have spurious wakeup!
		m_cv_uptr.wait(lock);
	}
	--m_count;
}
